export const STEP_lIST = [
  {
    title: '基本信息',
    status: 'wait',
  },
  {
    title: '一级菜单',
    status: 'wait',
  },
  {
    title: '二级菜单',
    status: 'wait',
  },
  {
    title: '分配角色',
    status: 'wait',
  },
];
export const STEP = {
  previous: -1,
  next: 1,
};

export const MODEL_TITLTE = {
  add: '新建应用',
  edit: '编辑应用',
};

export const operation_Type = {
  add: 1,
  edit: 2,
  delete: 3,
};

export const startSpaceReg = /^[^\s]+[\s]*.*$/; // 只有中间和最后能输入空格

// 3. deep compare
export function isObjDeepEqual(obj1, obj2) {
  const KEY = {
    OBJECT: 'object',
    ARRAY: 'array',
    FUNCTION: 'function',
  };
  const keys1 = Object.getOwnPropertyNames(obj1);
  const keys2 = Object.getOwnPropertyNames(obj2);
  if (keys1.length !== keys2.length) {
    return false;
  }
  const flag = keys1.every((key) => {
    const TYPE = typeof obj1[key];
    // escape null && self-call the function
    if (!!obj1[key] && TYPE === KEY.OBJECT) {
      return isObjDeepEqual(obj1[key], obj2[key]); // the recursion of funciton call
    }
    // array's case
    if (TYPE === KEY.ARRAY) {
      // check the length
      if (obj1[key].length !== obj2[key].length) {
        return false;
      }
      return obj1[key].every((child, index) => {
        const CHILD_TYPE = typeof child;
        // skip more deep compare, limit to 2
        if ([KEY.ARRAY].includes(CHILD_TYPE)) {
          return true;
        }
        // if function or object, then self-call
        if ([KEY.OBJECT, KEY.FUNCTION].includes(CHILD_TYPE)) {
          const OBJ2_CHILD = obj2[key][index];
          if (CHILD_TYPE !== typeof OBJ2_CHILD) {
            return false;
          }
          return isObjDeepEqual(child, OBJ2_CHILD);
        }
        // Normal value check
        if (child !== obj2[key][index]) {
          return false;
        }
        return true;
      });
    }
    // convert function to string, then compare the value
    if (TYPE === KEY.FUNCTION) {
      return obj1[key].toString() === obj2[key].toString();
    }
    // if unequal, return true
    if (obj1[key] !== obj2[key]) {
      return false;
    }
    return true;
  });
  // if found unequal, then return
  return flag;
}
